473,461 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parsing <content:encoded> through JS

Hello,

I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encoded> tag. I have tried getElementsbyTagName but its not
working.

Any suggstions?

Kashif

Apr 8 '06 #1
7 6668


kashaziz wrote:
I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encoded> tag. I have tried getElementsbyTagName but its not
working.


Is that well-formed XML with namespaces meaning content is a prefix and
declared e.g. with
xmlns:content="http://example.org/2006/whatever"
?
Then with Mozilla and with Opera use e.g.

xmlDocument.getElementsByTagNameNS('http://example.org/2006/whatever',
'encoded')
instead of getElementsByTagName.
For IE 6 and MSXML 3 you can use XPath e.g.
xmlDocument.setProperty('SelectionLanguage', 'XPath');
xmlDocument.setProperty('SelectionNamespaces',
'xmlns:content="http://example.org/2006/whatever"');
var encodedElements = xmlDocument.selectNodes('//content:encoded');

Both getElementsByTagNameNS and selectNodes can also be called on
element nodes instead on on the document node. But note that selectNodes
takes an XPath expression, use a relative expression e.g.
element.selectNodes('content:encoded')
or
element.selectNodes('.//content:encoded')
to find elements relative to the element the method is called on.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 8 '06 #2
Martin Honnen wrote:
kashaziz wrote:
I am here after head-banging with this issue for several days. I am
trying to parse a feed using JS and have stucked on the
<content:encoded> tag. I have tried getElementsbyTagName but its not
working.


Is that well-formed XML with namespaces meaning content is a prefix and
declared e.g. with
xmlns:content="http://example.org/2006/whatever"
?
Then with Mozilla and with Opera use e.g.

xmlDocument.getElementsByTagNameNS('http://example.org/2006/whatever',
'encoded')
instead of getElementsByTagName.
For IE 6 and MSXML 3 you can use XPath e.g.
[...]


The Gecko DOM has XPath support, too.

<URL:http://xulplanet.com/references/objref/>
<URL:http://kb.mozillazine.org/XPath>
<URL:http://developer.mozilla.org/en/docs/XPath>
PointedEars
Apr 8 '06 #3


Thomas 'PointedEars' Lahn wrote:

The Gecko DOM has XPath support, too.


Right, Opera 9 will also implement the W3C DOM Level 3 XPath API (only a
W3C note, not a recommendation) but to access elements in namespaced
documents safely getElementsByTagNameNS is sufficient and much easier to
use than the W3C DOM Level 3 XPath API.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 8 '06 #4
The Feed is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/1.5.2" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"


<channel>
<title>Apnijobs.com: Jobs in Pakistan</title>
<link>http://www.apnijobs.com</link>
<description>Work for pleasure, not for creating more work - Search
Jobs in Pakistan and around the World.</description>
<pubDate>Mon, 27 Mar 2006 10:35:13 +0000</pubDate>
<generator>http://wordpress.org/?v=1.5.2</generator>
<language>en</language>

<item>
<title>Teachers Required for Nursery / Kindergarten and Junior School
(Karachi)</title>
<link>http://www.apnijobs.com/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html</link>
<comments>http://www.apnijobs.com/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html#comments</comments>
<pubDate>Mon, 27 Mar 2006 10:34:17 +0000</pubDate>
<dc:creator>Ali Asgher</dc:creator>

<category>Teaching</category>
<category>Listing</category>
<category>Jobs</category>
<guid>http://www.apnijobs.com/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html</guid>
<description><![CDATA[<p>School of excellence requires teachers for
Nursery / Kindergarten and Junior school Science teach...</p>
]]></description>
<content:encoded><![CDATA[<p>School of excellence requires teachers
for Nursery / Kindergarten and Junior school Science teacher for
immediate appointment. </p>

<p>Contact 021-4981303, 4816345.</p>

<p>Address: D-2, Block-4, Gulshan-e-Iqbal, Karachi.</p>

<p>E-mail: so*@cyber.net.pk</p>
]]></content:encoded>
<wfw:commentRSS>http://www.apnijobs.com/teachers-required-for-nursery-kindergarten-and-junior-school-karachi.html/feed/</wfw:commentRSS>
</item>
--------------------------------------------------------------------------------------------------------

and the code is:
for (var i=0; i<this.feeditems.length; i++){
if(i==this.feed_id){
var feedfound=1
this.title[i]=this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue

this.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue

this.description[i]=this.feeditems[i].getElementsByTagName("description")[0].firstChild.nodeValue

this.pubdate[i]=this.feeditems[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue
tickercontent = "<a
href="+this.link[i]+">"+this.title[i]+"</a>"+"<br/>"

}
}

Apr 8 '06 #5


kashaziz wrote:
The Feed is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/1.5.2" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/" <content:encoded><![CDATA[<p>School of excellence requires teachers
for Nursery / Kindergarten and Junior school Science teacher for
immediate appointment. </p>

<p>Contact 021-4981303, 4816345.</p>

<p>Address: D-2, Block-4, Gulshan-e-Iqbal, Karachi.</p>

<p>E-mail: so*@cyber.net.pk</p>
]]></content:encoded>


Then use the already suggested code, the above is XML with namespaces so
with Mozilla and Opera make use of the W3C DOM Level 2 namespace aware
methods like getElementsByTagNameNS e.g.
var encodedElements = xmlDocument.getElementsByTagNameNS(
'http://purl.org/rss/1.0/modules/content/',
'encoded'
);
Then you get a DOM NodeList the same as with getElementsByTagName so you
should know how to loop through. Only note that the contents of those
content:encoded elements seems to be a single CDATA section node to
escape HTML markup snippets. You can read out that HTML markup snippets
as text (e.g. encodedElements[0].firstChild.data) but inside of a CDATA
section it will not be parsed into nodes.

And for IE 6/MSXML 3 you can use selectNodes and XPath 1.0 to get a DOM
NodeList as suggested
xmlDocument.setProperty('SelectionLanguage', 'XPath');
xmlDocument.setProperty('SelectionNamespaces',
'xmlns:content="http://purl.org/rss/1.0/modules/content/"');
var encodedElements = xmlDocument.selectNodes('.//content:encoded');
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 9 '06 #6
I have tried var encodedElements = xmldata.getElementsByTagNameNS(
"http://purl.org/rss/1.0/modules/content/", "encoded"); but it returns
a 0 length value.

Apr 11 '06 #7
Any suggestion guys?

Apr 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape...
2
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest...
17
by: ccdrbrg | last post by:
This is a rather general subject, I apologize. I am new to XHTML, CSS, et al and I am having trouble understanding the DTD and xml namespace declarations. For example: <!DOCTYPE html PUBLIC...
28
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
4
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt;...
12
by: Christian Roth | last post by:
Hello, I am merely asking this for my own understanding: Processing instruction's data part is not entity-aware, i.e. character and numercial entities are not resolved at parsing time. E.g., ...
4
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image...
5
by: magix | last post by:
Hi, with: <Input type="file"...> it will let the user to click to "browse" button to browse for files, question is how can I limit the file type to be only jpg and gif extension, when the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.